package com.next

class WorkflowInstanceStage
{
    Integer executionSequence
    String name
    Boolean canReject = true
    WorkflowInstance instance

    Date createdDate = new Date()
    Date modifiedDate = new Date()

    User createBy
    User modifyBy

    static hasMany = [conditions: WorkflowInstanceCondition, events: WorkflowInstanceEvent]

    static constraints = {
        executionSequence unique: ['instance'], min: 1, max: 10000
        name unique: ['instance']

        createBy nullable: true, blank: true
        modifyBy nullable: true, blank: true
        createdDate nullable: true, blank: true
        modifiedDate nullable: true, blank: true
    }

    static mappedBy = [conditions: 'stage']

    def springSecurityService

    def beforeInsert()
    {
        def username = springSecurityService?.getPrincipal()?.username
        createBy = User.findByUsername(username)
    }

    def beforeUpdate()
    {
        modifiedDate = new Date()
        def username = springSecurityService?.getPrincipal()?.username
        modifyBy = User.findByUsername(username)
    }
}
